﻿#ifndef CDBOPENGAUSSOPER_H
#define CDBOPENGAUSSOPER_H

#include "cdbbaseoper.h"
#include <QMap>

/***********************************************
* [className]   CDbOpengaussOper
* [func]        高斯数据库操作类
* [author]      jhb
* [date]        2023-12-18 17:03:07
* [Modification Log]
* Version               By              Notes
* v0.0.1                jhb             初次建立
************************************************/
class CDbOpengaussOper : public CDbBaseOper
{
public:
    enum enumKeyType
    {
        enKEYSET,               //关键字SET
        enKEYWHERE,             //关键字WHERE
        enKEYORDERBY,           //关键字ORDER BY
        enKEYLIMIT,             //关键字LIMIT
        enKEYIN,                //关键字IN
    };

    CDbOpengaussOper(const QString &sConnectInfo, const QString &sConnectName);
    CDbOpengaussOper(const CDataBaseConfig &cDbCfg);
    ~CDbOpengaussOper();

protected:
    //判断数据库表是否存在
    virtual bool isTableExist(CDbTableInfoMgr *pMgr);
    //获取库表名
    virtual QString getTableName(CDbTableInfoMgr *pMgr);
    //获取字段名
    virtual QString getFieldName(const QString &sSrc);
    virtual QString getFieldName(const QString &sSrc, CDbTableInfoMgr *pMgr);
    //解析追加字段名
    virtual QString analysisAppendSql(CDbTableInfoMgr *pMgr);
    //执行自定义语句
    virtual void handleCustomSql(CDbTableInfoMgr *pMgr);

private:
    //转义插入语句
    virtual QString analysisInsertSql(CDbTableInfoMgr *pMgr);
    //转义删除语句
    virtual QString analysisDeleteSql(CDbTableInfoMgr *pMgr);
    //转义更新语句
    virtual QString analysisUpdateSql(CDbTableInfoMgr *pMgr);
    //转义查询语句
    virtual QString analysisSelectSql(CDbTableInfoMgr *pMgr);

    //处理关键字WHERE
    virtual void handleWhere(CDbTableInfoMgr *pMgr);
    //处理关键字ORDER BY
    virtual void handleOrderby(CDbTableInfoMgr *pMgr);
    //处理关键字SET
    virtual void handleSet(CDbTableInfoMgr *pMgr);
    //处理关键字IN(子查询)
    virtual void handleIn(CDbTableInfoMgr *pMgr);
    //获取关键字索引
    int getKeyIndex(const int &nType, CDbTableInfoMgr *pMgr, QMap<int, QString> &mapIndex);
};

#endif // CDBOPENGAUSSOPER_H
